<template>
    <div class="tableList">
        <el-table :data="tableData" style="width: 100%;" max-height="350"
            :header-cell-style="{color:'#000',fontWeight:400,fontSize:'12px'}"
            :cell-style="{color:'#5a5a5a',fontSize:'12px',fontWeight:400}" v-loading="loading"
            element-loading-text="加载中" element-loading-background="rgba(250, 250, 250, 0.5)"
            element-loading-spinner="el-icon-loading" ref="tabList">
            <el-table-column label="序号" width="80">
                <template slot-scope="scope">
                    <span>{{(searchForm.page - 1) * (searchForm.limit) + scope.$index + 1}}</span>
                </template>
            </el-table-column>
            <el-table-column prop="createTime" label="发生时间" width="150" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="createUserName" label="发起人" width="100" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="typeName" label="联络灯类型" width="100" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="dealUserName" label="处理人" width="100" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="finishTime" label="完成时间" width="150" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="totalIntervalHour" label="持续时长(h)">
            </el-table-column>
            <el-table-column align="right">
                <template slot="header">
                    <my-button type="text" size="mini" icon="el-icon-upload2"  @btnClick="handleExportLampTimingDetail()">导出
                    </my-button>
                </template>
            </el-table-column>
            <div slot="empty">
                <el-empty :image-size="100"></el-empty>
            </div>
        </el-table>
        <el-pagination v-if="total" @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :page-sizes="[10,20,50,100]" :page-size="searchForm.limit" layout="total,prev, pager, next,sizes"
            :total="total" background>
        </el-pagination>
    </div>
</template>

<script>
    import {
        lampRequestList,
        exportLampTimingDetail
    } from '@/api/lampController'
    import fileDownload from "js-file-download";
    export default {
        data() {
            return {
                tableData: [],
                loading: false,
                total: 0
            }
        },
        props: {
            searchForm: {
                type: Object,
                default: () => ({})
            }
        },
        methods: {
            handleExportLampTimingDetail() {
                exportLampTimingDetail(this.searchForm).then(res => {
                    fileDownload(res, '联络灯时详情型表' + new Date().dateFormat('yyyyMMddhhmmss') + '.xlsx', 
                    'application/vnd.ms-excel;charset=UTF-8')
                })
            },
            //联络灯报表列表
            getLampRequestList(data) {
                this.loading = true
                lampRequestList(data).then(res => {
                    if (res.code == 200) {
                        this.tableData = res.data
                        this.total = res.count
                    }
                    this.loading = false
                })
            },
            //pageSize 改变时会触发
            handleSizeChange(val) {
                this.searchForm.limit = val
                this.getLampRequestList(this.searchForm)
            },
            //currentPage 改变时会触发
            handleCurrentChange(val) {
                this.searchForm.page = val
                this.getLampRequestList(this.searchForm)
            },
        },
    }
</script>

<style lang="less" scoped>
    .tableList {
        code {
            font-family: sans-serif;
        }
    }
</style>